package com.axonactive.yolo.dto;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.apache.log4j.Logger;

import com.axonactive.yolo.util.ConvertUnixTime;
import com.axonactive.yolo.util.Utils;

public class AirportDeparture {

	protected String code;
	protected String name;
	private String departureTime;
	private String departureTimeHHmmss;
	private String departureTimeDDmmYYYY;
	protected Airline airline;
	private DateTimeDescription departureTimeDescription;
	// this field is used for wego.
	private String localDepartureTime;
	
	private final static Logger LOGGER = Logger.getLogger(AirportDeparture.class);

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Airline getAirline() {
		return airline;
	}

	public void setAirline(Airline airline) {
		this.airline = airline;
	}

	public String getDepartureTime() {
		return departureTime;
	}

	public void setDepartureTime(String departureTime) {
		this.departureTime = departureTime;
		this.departureTimeDescription = new DateTimeDescription();
		if (this.localDepartureTime != null) {// 2014/02/25 20:00 +0700
			String monthString = this.localDepartureTime.substring(5, 7);
			String dateString = this.localDepartureTime.substring(8, 9);
			String yearString = this.localDepartureTime.substring(0, 4);
			String hourString = this.localDepartureTime.substring(11, 13);
			String minuteString = this.localDepartureTime.substring(14, 16);
			this.departureTimeDescription
					.setNAM(Utils.convertToInt(yearString));
			this.departureTimeDescription.setTHANG(Utils
					.convertToInt(monthString));
			this.departureTimeDescription.setNGAY(Utils
					.convertToInt(dateString));
			this.departureTimeDescription
					.setGIO(Utils.convertToInt(hourString));
			this.departureTimeDescription.setPHUT(Utils
					.convertToInt(minuteString));

		} else {

			ConvertUnixTime convertUnixTime = new ConvertUnixTime();
			this.departureTimeDescription = convertUnixTime
					.getLocalTimeBaseOnJDK(this.departureTime);
		}

	}

	/**
	 * @return dd/MM/yyyy
	 */
	public String getDepartureTimeByDDMMYY() {
		if (departureTimeDescription == null) {
			return "";
		} else {
			return departureTimeDescription.getNGAY() + "/"
					+ departureTimeDescription.getTHANG() + "/"
					+ departureTimeDescription.getNAM();
		}
	}

	/**
	 * @return yyyy/MM/dd
	 */
	public String getDepartureTimeYYYYMMDD() {
		if(departureTimeDDmmYYYY!=null){
			String date = departureTimeDDmmYYYY.replaceAll("-", "/");
			return date;
		}
		if (departureTimeDescription == null) {
			return "";
		} else {
			String thang = Utils.formatNumber(departureTimeDescription.getTHANG());
			String ngay=Utils.formatNumber(departureTimeDescription.getNGAY());
			return departureTimeDescription.getNAM() + "/" + thang + "/"
					+ ngay;
		}
	}

	/**
	 * @return HH:mm
	 */
	public String getDepartureTimeByHHmm() {
		if(departureTimeHHmmss!=null){
			return departureTimeHHmmss.substring(0, 5);
		}
		if (departureTimeDescription == null) {
			return "";
		} else {
			String gio=Utils.formatNumber(departureTimeDescription.getGIO());
			String phut=Utils.formatNumber(departureTimeDescription.getPHUT());
			return  gio+":"+phut;
		}
	}

	public void setDepartureTimeDescription() {
	}

	public void setLocalDepartureTime(String localDepartureTimeStr) {
		this.localDepartureTime = localDepartureTimeStr;
	}

	
	/**
	 * @return the departureTimeHHmmss (20:00:00)
	 */
	public String getDepartureTimeHHmmss() {
		return departureTimeHHmmss;
	}

	/**
	 * @return the departureTimeDDmmYYYY (31-12-2014)
	 */
	public String getDepartureTimeDDmmYYYY() {
		return departureTimeDDmmYYYY;
	}

	/**
	 * @param departureTimeHHmmss the departureTimeHHmmss to set
	 */
	public void setDepartureTimeHHmmss(String departureTimeHHmmss) {
		this.departureTimeHHmmss = departureTimeHHmmss;
	}

	/**
	 * @param departureTimeDDmmYYYY the departureTimeDDmmYYYY to set
	 */
	public void setDepartureTimeDDmmYYYY(String departureTimeDDmmYYYY) {
		this.departureTimeDDmmYYYY = departureTimeDDmmYYYY;
	}

	public static void main(String[] args) {
		NumberFormat formatter = new DecimalFormat("00");
		String number = formatter.format(12);
		LOGGER.info(number);

		;

	}
	
}
